package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.service.PoemService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/7/26
 **/

@Controller
@ResponseBody
@RequestMapping("poem")

public class PoemController {
    @Autowired
    PoemService poemService;

    @ApiOperation("分页无条件查询诗词")
    @RequestMapping(value = "/getBasicList", method = {RequestMethod.GET})
    public BaseModel getBasicList(
            @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        poemService.getpoemlist(pageQueryModel, model);
        return model;
    }

    @ApiOperation("根据主要景点id条件诗词")
    @RequestMapping(value = "/getListByMainPlace", method = {RequestMethod.GET})
    public BaseModel getListByMainPlace(@ApiParam("main_place_id") @RequestParam(value = "main_place_id", required = true) int main_place_id,
                                        @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        poemService.getPoemByPlaceId(main_place_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("分页查询more条件诗词")
    @RequestMapping(value = "/getListByMore", method = {RequestMethod.GET})
    public BaseModel getListByMore(@ApiParam("more") @RequestParam(value = "more", required = true) String more,
                                   @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        poemService.getpoemByMore(more, pageQueryModel, model);
        return model;
    }

    @ApiOperation("根据id查询诗词")
    @RequestMapping(value = "/getPoemBasic", method = {RequestMethod.GET})
    public BaseModel getPostBasic(@ApiParam("poem_id") @RequestParam(value = "poem_id", required = true) Integer poem_id,
                                  @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        poemService.getpoembasic(poem_id, model);
        return model;
    }

    @ApiOperation("根据诗词内容查询诗词")
    @RequestMapping(value = "/getPoemText", method = {RequestMethod.GET})
    public BaseModel getPostText(@ApiParam("text") @RequestParam(value = "text", required = true) String text
    ) throws Exception {
        BaseModel model = new BaseModel();
        poemService.getpoemByText(text, model);
        return model;
    }

    @ApiOperation("搜索诗词信息")
    @RequestMapping(value = "/searchPoem", method = {RequestMethod.GET})
    public BaseModel searchPoem(@ApiParam("text") @RequestParam(value = "text", required = true) String text
    ) throws Exception {
        BaseModel model = new BaseModel();
        poemService.searchPoem(text, model);
        return model;
    }

}
